// 参数json对象解析
export function tansParams(params){
    let result = ''
    for (const propName of Object.keys(params)) {
      const value = params[propName];
      var part = encodeURIComponent(propName) + "=";
      if (value !== null && value !== "" && typeof (value) !== "undefined") {
        if (typeof value === 'object') {
          for (const key of Object.keys(value)) {
            if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
              let params = propName + '[' + key + ']';
              var subPart = encodeURIComponent(params) + "=";
              result += subPart + encodeURIComponent(value[key]) + "&";
            }
          }
        } else {
          result += part + encodeURIComponent(value) + "&";
        }
      }
    }
    return result
  }


  //excel导出功能
  export function downloadExcel(url, params, target = "_self") {
    if (!url) {
      return;
    }
    let token = localStorage.getItem("access_token");
    let base64EncodedToken = btoa(token);
    params.authinfo =  encodeURIComponent(base64EncodedToken);
    const dowa = document.createElement("a");
    dowa.href = process.env.VUE_APP_API_BASE_URL + url + "?" + tansParams(params);
    dowa.target = target;
    document.body.appendChild(dowa);
    dowa.click();
    document.body.removeChild(dowa);
  }

